# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=openntpd
pkgver=6.8_p1
_pkgver=${pkgver/_/}
pkgrel=9
pkgdesc="Lightweight NTP server ported from OpenBSD"
url="http://www.openntpd.org/"
subpackages="openntpd-doc openntpd-openrc"
makedepends="libretls-dev linux-headers bsd-compat-headers
	autoconf automake libtool byacc"
arch="all"
license="ISC"
options="!check"
source="https://ftp.openbsd.org/pub/OpenBSD/OpenNTPD/openntpd-$_pkgver.tar.gz
	ntp-user.patch
	libtls-standalone.patch
	$pkgname.confd
	$pkgname.initd
	"
builddir="$srcdir/$pkgname-$_pkgver"

prepare() {
	default_prepare
	autoreconf -vif
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--localstatedir=/var \
		--mandir=/usr/share/man \
		--sysconfdir=/etc \
		--with-privsep-user=ntp \
		--enable-https-constraint
	make
}

package() {
	make install DESTDIR="$pkgdir"

	mkdir -p "$pkgdir"/var/empty
	install -Dm755 "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/"$pkgname"
	install -Dm644 "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/"$pkgname"
	rmdir "$pkgdir"/var/run
}

sha512sums="
200056bedb9c757aae1ce5d3f6655175ec058cb479429fe4704955f3a3fa15e8a9cb578ae4898ddb4cfc08c9742bbab6a7c92b5e569f06a148e40c448360b58f  openntpd-6.8p1.tar.gz
290311e5cd074d5bd1e6374ba9b4776e4acf792d47011c43412e236766b73be2b0e5f0091bd3ad79d0b637754531889b199e66c64952765bbcd1bade0d2ebe94  ntp-user.patch
4b27edb9b778a8a0437735e010f0606cd03a46d10bb054a6527929d46de44ba470bc81017cb2a61956fc8049879e498aadf545a89a35be1237e26eeac98ef3e3  libtls-standalone.patch
a893f0a46509ef7a868cb153e90701cd67e5e08df0cd1cf50f3a2b8da027cbd3b3fcde77d3dd4c3e8c8135c54f4aab61d5f85c02bb0199bc26a4631ffc431f64  openntpd.confd
009eb7c7cf290c9302d9585ce7dffb2195e7e73c8bd3274b158efde10b537919c5dc4a47038f2fca6d650bcd79e8333395faa06d98f28327a328368fd59a1618  openntpd.initd
"
